/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.viweb.storemanager.entity;

import com.viweb.storemanager.core.PropertyIndex;
import com.viweb.storemanager.core.SafeObject;
import java.text.Collator;
import java.text.RuleBasedCollator;
import java.util.Locale;

/**
 *
 * @author nhchung
 */
public class SaleDetail extends BaseEntity implements Comparable, Cloneable, SafeObject, PropertyIndex {
    //khai báo biến

    protected Object cloner;
    private SaleInvoice invoice;
    private Product product;
    private int number;
    private double price;
    private String unit;

    //khai báo hàm khởi tạo
    public SaleDetail() {
    }

    /**
     * @return the invoice
     */
    public SaleInvoice getInvoice() {
        return invoice;
    }

    /**
     * @param invoice the invoice to set
     */
    public void setInvoice(SaleInvoice invoice) {
        this.invoice = invoice;
    }

    /**
     * @return the product
     */
    public Product getProduct() {
        return product;
    }

    /**
     * @param product the product to set
     */
    public void setProduct(Product product) {
        this.product = product;
    }

    /**
     * @return the number
     */
    public int getNumber() {
        return number;
    }

    /**
     * @param number the number to set
     */
    public void setNumber(int number) {
        this.number = number;
    }

    /**
     * @return the price
     */
    public double getPrice() {
        return price;
    }

    /**
     * @param price the price to set
     */
    public void setPrice(double price) {
        this.price = price;
    }

    /**
     * @return the unit
     */
    public String getUnit() {
        return unit;
    }

    /**
     * @param unit the unit to set
     */
    public void setUnit(String unit) {
        this.unit = unit;
    }

    public Object getCloner() {
        return this.cloner;
    }

    public boolean validate() {

        return true;
    }

    public Object getPropertyValue(int index) {
        String value = "";
        switch (index) {
            case 1:
                value = getInvoice().toString();
                break;
            case 2:
                value = getProduct().getName();
                break;
            case 3:
                value = String.valueOf(getNumber());
            case 4:
                value = String.valueOf(getPrice());
                break;
            case 5:
                value = getUnit();
                break;
            case 6:
                value = getDatemodifies().toString();
                break;
            case 7:
                value = String.valueOf(getStatus());
                break;
            case 8:
                value = getNote();
                break;
        }
        return value;
    }

    public void setPropertyValue(int index, Object value) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public Class getPropertyClass(int index) {
        return String.class;
    }

    public int compareTo(Object object) {
        if (!(object instanceof WareHouse)) {
            throw new ClassCastException("Ngoại lệ: đối tượng thức uống không hợp lệ!");
        }

        RuleBasedCollator viCollator = (RuleBasedCollator) Collator.getInstance(new Locale("vi"));
        return viCollator.compare(this.getId(), ((SaleDetail) object).getId());
    }

    public void backup() {
        try {
            this.cloner = this.clone();
        } catch (CloneNotSupportedException ex) {
        }
    }

    public void restore() {
        this.setId(((SaleDetail) getCloner()).getId());
    }

    @Override
    public String toString() {
        return String.valueOf(this.getId());
    }
}
